package com.gupt.youhd.service.impl;/*
@author name
@data 2023/4/24-22:30
*/


import cn.hutool.json.JSONUtil;
import com.gupt.youhd.common.StringConstant;
import com.gupt.youhd.entity.User;
import com.gupt.youhd.mapper.SchoolMapper;
import com.gupt.youhd.mapper.ShopMapper;
import com.gupt.youhd.entity.School;
import com.gupt.youhd.entity.Shop;
import com.gupt.youhd.service.ProductService;
import com.gupt.youhd.util.RedisUtils;
import com.gupt.youhd.util.YouHDUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    SchoolMapper schoolMapper;

    @Autowired
    ShopMapper shopMapper;

    @Autowired
    private YouHDUtils youHDUtils;

    @Override
    public List<Shop> retrieveProductBySchoolName(HttpServletRequest request) {

        User user = youHDUtils.getUser(request);

        //查询当前学校id
        School school = schoolMapper.retrieveSchoolBySchoolName(user.getSchoolName());
        int schoolId = school.getSchoolId();

        //根据学校id查找对应学校商品信息
        List<Shop> shops = shopMapper.retrieveShopProductBySchoolId(schoolId);

        if(shops != null){
            log.info("对应商品列表为：{}", shops);
        }
        return shops;
    }

    @Override
    public List<Shop> mohuRetrieveShopProductBySchoolIdAndBrief(HttpServletRequest request, String keyword) {

        User user = youHDUtils.getUser(request);

        //查询当前学校id
        School school = schoolMapper.retrieveSchoolBySchoolName(user.getSchoolName());
        int schoolId = school.getSchoolId();

        List<Shop> shops = shopMapper.mohuRetrieveShopProductBySchoolIdAndBrief(schoolId, keyword);

        if(shops != null){
            log.info("模糊查询商品列表为：{}",shops);
        }
        return shops;
    }
}
